<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <meta name="layout" content="save_undo" />
        <title>${Inter.printOut('Show Project',session.language)} ${fieldValue(bean:projectInstance, field:'name')}</title>
    </head>
    <body>
        <div class="undernav">
            <span class="menuButton"><g:link class="create" action="create">${Inter.printOut('New Project',session.language)}</g:link></span>
            <!-- This is the help button. -->
            <%  def help = Help.findByNameAndLanguage("project_show", session.language)
            def helplink = createLink(action:'show', controller:'help', id: help.id )%>
            <a href="#" onClick="MyWindow=window.open('${helplink}','Help','width=350,height=450'); return false;">${Inter.printOut('Help',session.language)}</a>
            <!-- This is the end of the help button. -->
        </div>
       <!-- display only if the current mode allows it -->
           <!--   <div class="mode">
              <span style="font-weight:bold">
              <g:if test="${session.mode == null || session.mode.equalsIgnoreCase('sandbox')}">
                ${Inter.printOut('Sandbox mode',session.language)}
              <g:btnSaveUndo currentView="show" currentController="project" idProject="${projectInstance?.id}" /> 
              </g:if>
              <g:else>
                ${Inter.printOut('Budget mode',session.language)}
              </g:else>
                </span>
            </div> -->
       
        <div class="body" style="width:98%;">
          <g:javascript src="jquery.livequery.js" />
          <g:javascript src="budget/editFigures.js" />
          <g:link class="hidden urlUpdateIncome" controller="project" action="updateIncome"></g:link>
          <g:link class="hidden urlUpdateVariableCost" controller="project" action="updateVariableCost"></g:link>
          <g:link class="hidden urlUpdate" controller="project" action="updateExpenditure"></g:link>
          <g:link class="hidden urlUpdateHours" controller="project" action="updateHours"></g:link>
          <input type="hidden" value="${fieldValue(bean:projectInstance, field:'id')}" id="projectId" />
           <!-- <h1>${Inter.printOut('Project',session.language)}: ${fieldValue(bean:projectInstance, field:'name')}</h1> -->
            <g:if test="${flash.message}">
            <div class="message">${flash.message}</div>
            </g:if>
            <div class="showProject">
              
              <div style="float:left; width:100%;margin-top:10px;">
                <div class="projectDetails" style="position:static;float:left;width:40%;margin-top:0px;">
                  <h2>${Inter.printOut('Project',session.language)}: ${fieldValue(bean:projectInstance, field:'name')}</h2>
                  <table>
                    <tbody>
                        <tr class="prop">
                            <td valign="top" class="name">${Inter.printOut('Activity Id',session.language)}:</td>

                            <td valign="top" class="value">${fieldValue(bean:projectInstance, field:'activityId')}</td>

                        </tr>

                      <!--  <tr class="prop">
                            <td valign="top" class="name">${Inter.printOut('name',session.language)}:</td>

                            <td valign="top" class="value">${fieldValue(bean:projectInstance, field:'name')}</td>

                        </tr> -->

                        <tr class="prop">
                            <td valign="top" class="name">${Inter.printOut('Description',session.language)}:</td>

                            <td valign="top" class="value">${fieldValue(bean:projectInstance, field:'description')}</td>

                        </tr>
                    <!--
                        <tr class="prop">
                            <td valign="top" class="name">Amount Of Hour:</td>

                            <td  valign="top" style="text-align:left;" class="value">
                                <ul>
                                <g:each var="a" in="${projectInstance.amountOfHour}">
                                    <li><g:link controller="whoa" action="show" id="${a.id}">${a?.encodeAsHTML()}</g:link></li>
                                </g:each>
                                </ul>
                            </td>

                        </tr>
                    -->
                        <tr class="prop">
                            <td valign="top" class="name">${Inter.printOut('Area',session.language)}:</td>

                            <td valign="top" class="value"><g:link controller="area" action="show" id="${projectInstance?.area?.id}">${projectInstance?.area?.encodeAsHTML()}</g:link></td>

                        </tr>
                        <tr class="prop">
                            <td valign="top" class="name">${Inter.printOut('Start Date',session.language)}:</td>

                            <td valign="top" class="value"><g:formatDate date="${projectInstance.startDate}" format="yyyy-MM-dd" /></td>

                        </tr>
                        <tr class="prop">
                            <td valign="top" class="name">${Inter.printOut('End Date',session.language)}:</td>

                            <td valign="top" class="value"><g:formatDate date="${projectInstance.endDate}" format="yyyy-MM-dd" /></td>

                        </tr>
                    </tbody>
                </table>
                  <%
          def a = session.access
          a.refresh()
          %>
                  <div class="buttons" style="margin:0px;">
                <g:if test="${(!session.mode.equalsIgnoreCase('budget')) || (session.mode.equalsIgnoreCase('budget') && !a.isBudgetLocked())}">
                    <g:form>
                        <input type="hidden" name="id" value="${projectInstance?.id}" />
                        <span class="button"><g:actionSubmit class="edit" value="${Inter.printOut('Edit',session.language)}" action="Edit"/></span>
                        <span class="button"><g:actionSubmit class="delete" onclick="return confirm('${Inter.printOut('Sure',session.language)}');" value="${Inter.printOut('Delete',session.language)}" action="Delete"/></span>
                    </g:form>
                </g:if>
                    <g:else>
                      Budget locked, project not editable
                    </g:else>
                   </div>
                  
                </div>
                
                <div class="varibleCosts"style="position:static;float:left;width:40%;margin-left:20px">
                
                <h2>${Inter.printOut('Variable Costs',session.language)}</h2>
                <table class="">
                    <tbody>
                       <g:each in="${projectInstance.currentBudget().variableCosts.sort {it.category.name}}" status="i" var="variableCost">
                        <tr class="prop">
                            <td valign="top" class="name">${Inter.printOut(variableCost.category.name,session.language)}</td>
                            <td valign="top" class="value">
                              <g:if test="${(!session.mode.equalsIgnoreCase('budget')) || (session.mode.equalsIgnoreCase('budget') && !a.isBudgetLocked())}">
                                <span id="variableCost_${variableCost.id}" class="variableCostFigures">${variableCost.amount}
                                  <img alt="edit" style="vertical-align:text-bottom;" src="${resource(dir:'images/skin',file:'pencil.png')}"/>
                                </span>
                              </g:if>
                              <g:else>
                                <span id="variableCost_${variableCost.id}">${variableCost.amount}
                                </span>
                              </g:else>
                            </td>
                        </tr>
                       </g:each>
                    </tbody>
                </table>


                </div>
                </div>

                
              <div style="float:left; width:100%; margin-top:10px;">
                <div class="projectIncome" style="position:static;float:left; width:40%">
                 <h2>${Inter.printOut('Incomes',session.language)}</h2>
                <table class="" style="table-layout: fixed">
                  <thead>
                    <tr>
                      <th>${Inter.printOut('Known Incomes',session.language)}</th>
                      <th>${Inter.printOut('Expected Incomes',session.language)}</th>
                      <th>${Inter.printOut('Total Incomes',session.language)}</th>
                    </tr>
                  </thead>
                    <tbody>
                        <tr class="prop">
                            <td valign="top" class="value">
                              <g:if test="${(!session.mode.equalsIgnoreCase('budget')) || (session.mode.equalsIgnoreCase('budget') && !a.isBudgetLocked())}">
                                <span id="knownIncome" class="incomeFigures">
                                  ${projectInstance?.currentBudget()?.knownTotalIncome}
                                  <img alt="edit" style="vertical-align:text-bottom;" src="${resource(dir:'images/skin',file:'pencil.png')}"/>
                                </span>
                              </g:if>
                              <g:else>
                                <span id="knownIncome" >
                                  ${projectInstance?.currentBudget()?.knownTotalIncome}
                                </span>
                              </g:else>
                            </td>
                            <td valign="top" class="value">
                              <g:if test="${(!session.mode.equalsIgnoreCase('budget')) || (session.mode.equalsIgnoreCase('budget') && !a.isBudgetLocked())}">
                                <span id="expectedIncome" class="incomeFigures">
                                  ${projectInstance?.currentBudget()?.expectedTotalIncome}
                                  <img alt="edit" style="vertical-align:text-bottom;" src="${resource(dir:'images/skin',file:'pencil.png')}"/>
                                </span>
                              </g:if>
                              <g:else>
                                <span id="expectedIncome">
                                  ${projectInstance?.currentBudget()?.expectedTotalIncome}
                                </span>
                              </g:else>
                            </td>
                            <td valign="top" class="value"><span id="totlalIncome" class="">${projectInstance?.currentBudget()?.calcTotalIncome()}</span></td>
                        </tr>
                    </tbody>
                  </table>
                </div>
                <div class="projectExpenditures" style="position:static;float:left;width:40%;margin-left:20px;">
                 <h2>${Inter.printOut('Expenditures',session.language)}</h2>
                  <table class="" style="table-layout: fixed">
                    <thead>
                      <tr>
                        <th>${Inter.printOut('Known Variable cost',session.language)}</th>
                        <th>${Inter.printOut('Expected Variable cost',session.language)}</th>
                        <th>${Inter.printOut('Fixed Cost',session.language)}</th>
                      </tr>
                    </thead>
                    <tbody>
                        <tr class="prop">
                            
                          <td valign="top" class="value">
                            <g:if test="${(!session.mode.equalsIgnoreCase('budget')) || (session.mode.equalsIgnoreCase('budget') && !a.isBudgetLocked())}">
                              <span id="knownExpenditure" class="expenditureFigures">
                                ${projectInstance?.currentBudget()?.knownVariableCost}
                                <img alt="edit" style="vertical-align:text-bottom;" src="${resource(dir:'images/skin',file:'pencil.png')}"/>
                              </span>
                            </g:if>
                            <g:else>
                              <span id="knownExpenditure">
                                ${projectInstance?.currentBudget()?.knownVariableCost}
                              </span>
                            </g:else>
                          </td>
                            <td valign="top" class="value"><span id="variableCost" class="">${projectInstance?.currentBudget()?.calcTotalVariableCost()}</span></td>
                            <td valign="top" class="value"><span id="fixedCost" class="">${projectInstance?.currentBudget()?.calcTotalFixedCost()}</span></td>
                        </tr>
                    </tbody>
                </table>
                  <span style="float:right;">Balance: ${projectInstance?.calcCurrentBalance()}</span>
        
                </div>
                <div class="projectMembers" style="float:left; width:100%">
                  <h2>${Inter.printOut('Members',session.language)}</h2>
                  <table style="table-layout: fixed">
                    <tbody>
                      <tr>
                        <th>${Inter.printOut('name',session.language)}</th>
                        <th>${Inter.printOut('Salary',session.language)}</th>
                        <th>${Inter.printOut('Hours in project',session.language)}</th>
                        <th>${Inter.printOut('Cost',session.language)}</th>
                      </tr>
                      <g:each var="m" in="${projectInstance.amountOfHour}">

                          <tr>
                            <td><g:link action="show" controller="employee" id="${m.member.id}">${m.member.firstName} ${m.member.lastName}</g:link></td>
                            <td><g:formatNumber number="${m.member.salary}" format="SEK ##,##0" /></td>
                            <td><span class="hoursFigures" id="updateHours" title="${m.id}">${m.hours}</span></td>
                            <td>${m.calculateCost()}</td>
                          </tr>
                      </g:each>
                    </tbody>
                  </table>


                <g:if test="${(!session.mode.equalsIgnoreCase('budget')) || (session.mode.equalsIgnoreCase('budget') && !a.isBudgetLocked())}">
                  <div class="buttons" style="margin:0px;">
                      <g:form>
                          <input type="hidden" name="id" value="${projectInstance?.id}" />
                          <span class="button"><g:actionSubmit action ="add_employee" class="add_employee"  value="${Inter.printOut('Add Employee',session.language)}" /></span>
                          <g:if test="${numberOfEmployees > 0}">
                            <span class="button"><g:actionSubmit action ="delete_employee" class="delete_employee"  value="${Inter.printOut('Remove Employee',session.language)}" /></span>
                          </g:if>
                       </g:form>
                  </div>
                </g:if>
                  </div>
                </div>
              </div>
              
              
            </div>



            <div class="dialog">

              
             

                

              
        
         
      </div>
        </div>
    </body>
</html>
